import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_first_project/api/home.dart';
import 'package:flutter_first_project/pages/home/components/home_list.dart';
import 'package:flutter_first_project/pages/home/components/home_nav.dart';
import 'package:flutter_first_project/utils/TokenManager.dart';
import 'package:flutter_first_project/utils/toast.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<HomePage> {
  // 社区公告列表
  List communityNoticeList = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 获取社区公告列表
    getCommunityNoticeList();
  }

  // 获取社区公告列表
  getCommunityNoticeList() async {
    final res = await getAnnounceListAPI();
    setState(() {
      communityNoticeList = res;
    });
    // 提示用户
    PrompAction.showInfo('获取社区公告列表成功');
    // print(res);
  }

  Timer? timer;
  final _count = 10;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('享 + 社区'),
        centerTitle: true,
        backgroundColor: Colors.transparent, // 背景色透明
      ),
      body: Padding(
        padding: const EdgeInsets.all(10.0),
        child: ListView(children: [
          Row(
            children: [
              ElevatedButton(
                  onPressed: () {
                    tokenManager.setToken('21123');
                    PrompAction.showInfo('设置token成功');
                  },
                  child: const Text('设置token')),
              ElevatedButton(
                onPressed: () {
                  // 开启定时器的逻辑
                
                  PrompAction.showInfo('开启定时器');
                },
                child: const Text('开启定时器'),
              ),
              ElevatedButton(
                onPressed: () {
                  // 关闭定时器的逻辑
                  PrompAction.showInfo('关闭定时器');
                },
                child: const Text('关闭定时器'),
              ),
              ElevatedButton(
                onPressed: () {
                  // 延时器的逻辑
                  Future.delayed(const Duration(seconds: 2), () {
                    PrompAction.showInfo('延时器');
                  });
                },
                child: const Text('延时器'),
              ),
            ],
          ),

          HomeNav(), // 导航
          ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(10.0)), // 圆角
            child: Image.asset('assets/images/banner@2x.jpg'),
          ),
          HomeList(notifyList: communityNoticeList)
        ]), // 内边距
      ),
    );
  }
}
